package com.taxi.management.service.Impl;

import com.taxi.management.dao.DriverDetailDao;
import com.taxi.management.dao.UserDao;
import com.taxi.management.entity.DriverDetailEntity;
import com.taxi.management.service.DriverDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class DriverDetailServiceImpl implements DriverDetailService {
    @Autowired
    private DriverDetailDao driverDetailDao;
    @Autowired
    private UserDao userDao;
    @Override
    public int insert(DriverDetailEntity entity) {
        Integer userId = entity.getUserId();
        if (userDao.getUserById(userId) == null) {
            throw new RuntimeException("无法添加司机信息：用户不存在！");
        }
        return driverDetailDao.insert(entity);
    }

    @Override
    public int deleteById(Integer driverId) {
        return driverDetailDao.deleteById(driverId);
    }

    @Override
    public int update(DriverDetailEntity entity) {
        return driverDetailDao.update(entity);
    }

    @Override
    public DriverDetailEntity selectById(Integer driverId) {
        return driverDetailDao.selectById(driverId);
    }

    @Override
    public List<DriverDetailEntity> selectAll() {
        return driverDetailDao.selectAll();
    }

    @Override
    public List<DriverDetailEntity> selectByPage(String username,int start, int limit) {
        return driverDetailDao.selectByPage( username,start, limit);
    }

    @Override
    public int getTotalCount() {
        return driverDetailDao.selectCount();
    }
}




